<!DOCTYPE html>
<html  class="iframe-h">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>回调管理中心</title>
    <link rel="stylesheet" type="text/css" href="../../static/admin/layui/css/layui.css"/>
    <link rel="stylesheet" type="text/css" href="../../static/admin/css/admin.css"/>
</head>
<body  class="iframe-h">
<div class="wrap-container email-wrap clearfix">
    <div class="demoTable">
        搜索url：
        <div class="layui-inline">
            <input class="layui-input" name="url" id="search-url" autocomplete="off" style="width: 400px;">
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;
        taskId：
        <div class="layui-inline">
            <input class="layui-input" name="url" id="search-taskId" autocomplete="off" style="width: 430px;">
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
        <button class="layui-btn" id="refresh-btn" style="float: right">刷新页面</button>
    </div>
    <table class="layui-hide" id="LAY_table_futuretask" lay-filter="demo"></table>
    <script type="text/html" id="barDemo">
        <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="resend">立即发起</a>
    </script>
</div>
<script src="../../static/admin/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<script>
    layui.use('table', function() {
        var table = layui.table;
        table.render({
            elem: '#LAY_table_futuretask'
            ,url:'/manager/getFutureTasks'
            ,method:'post'
            ,cols: [[
                {field:'url',title: 'url'}
                ,{field:'taskId',title: 'taskId', width: 90}
                ,{field:'requestMethod',title: '请求方式', width: 90}
                ,{field:'requestParam', title: '请求参数'
                    ,templet: function(item){
                        return JSON.stringify(item.requestParam)
                    }
                }
                ,{field:'sourceIp',title: '请求IP', width: 120}
                ,{field:'success',title: '是否成功', width: 90
                    ,templet: function(item){
                        return item.success ? '是':'否'
                    }
                }
                ,{field:'callCount',title: '重试次数', width: 90}
                ,{field:'limitCallCount',title: '限制次数', width: 90}
                ,{field:'createDate',title: '创建时间', width: 170}
                ,{field:'expireTime',title: '剩余时间', width: 90}
                ,{title: '操作', toolbar: '#barDemo', width: 100}
            ]]
            ,id: 'LAY_table_futuretask'
            ,page: true
            ,parseData: function(res){ //将原始数据解析成 table 组件所规定的数据
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.count, //解析数据长度
                    "data": res.data.resultList //解析数据列表
                };
            }
        });

        var $ = layui.$, active = {
            reload: function(){
                var url = $('#search-url');
                var taskId = $('#search-taskId');
                //执行重载
                table.reload('LAY_table_futuretask', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        url: url.val()
                        ,taskId: taskId.val()
                    }
                });
            }
        };

        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('#refresh-btn').on('click', function () {
            var url = $('#search-url');
            var taskId = $('#search-taskId');
            url.val('');
            taskId.val('');
            table.reload('LAY_table_futuretask', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                ,where: {
                    url: url.val()
                    ,taskId: taskId.val()
                }
            });
        })

        //监听工具条
        table.on('tool(demo)', function(obj){
            var data = obj.data;
            if(obj.event === 'resend') {
                var url = $('#search-url');
                var taskId = $('#search-taskId');
                $.post("/manager/retry",
                    {
                        taskId: data.taskId
                    },
                    function(data){
                        layer.alert(data);
                        table.reload('LAY_table_futuretask', {
                                where: {
                                    url: url.val()
                                    ,taskId: taskId.val()
                                }
                            }
                        );
                    });
            }
        });
    });
</script>
</body>
</html>